import Vue from "vue";
import VueRouter from "vue-router";
import Main from '../Views/Main'
import Login from '../Views/Login.vue'
import Cookie from 'js-cookie'
import Img from '../Views/Img.vue'
import Home from '../Views/Home.vue'
import Video from "@/Views/Video.vue";
import PageOne from "@/Views/PageOne.vue";
import PageTwo from "@/Views/PageTwo.vue";
import Register from "@/Views/Register.vue";
import User from "@/Views/User.vue"
import Warn from "@/Views/Warn.vue";
import short from "@/Views/short.vue";
import videoList from "@/components/videoList.vue";
import upvideo from "@/Views/upvideo/upvideo.vue";
import History from "@/components/History.vue";
import Cookies from "vue-cookies";
import indexu from "@/Views/user/index.vue";
import subvideo from "@/Views/upvideo/sbuvideo.vue";
import client from "@/Views/client/index.vue";
Vue.use(VueRouter)
Vue.use(Cookies)
const routes = [
    // 主路由
    {
        path: '/',
        name:'Main',
        component: Main,
        redirect: '/client', // 重定向
        children: [
            // 子路由
            // { path: '/home', name: 'home', component: Home }, // 首页
            { path: '/video', name: 'video', component: Video }, //
            { path: '/user', name: 'user', component: User }, //
            // { path: '/home', name: 'home', component: Home }, // 首页
            { path: '/page1', name: 'page1', component: PageOne }, // 页面1
            { path: '/page2', name: 'page2', component: PageTwo }, // 页面2
            { path: '/warn', name: 'warn', component: Warn }, //
            { path: '/short', name: 'short', component: short },
            { path: '/vlist', name: 'vlist', component: videoList },
            { path: '/subvideo', name: 'subvideo', component: upvideo },
            { path: '/his', name: 'his', component:  History},
            { path: '/infor', name: 'user', component:  indexu},
            { path: '/checkv', name: 'check', component:  subvideo},
        ]
    },
    { path: '/client', name: 'client', component: client },

    {
        path: '/login',
        name: 'login',
        component: Login
    },
    {
        path: '/reg',
        name: 'register',
        component: Register
    }
]

const router = new VueRouter({
    routes
})

// 路由守卫:全局前置导航守卫
router.beforeEach((to, from, next) => {
    //获取token
if(Cookies.isKey("user")){
    next()
}else{
    if(to.path=='/login'||to.path=='/reg'){
        next()
    }else{

        next('/login')
    }
}

})


export default router